home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / libkb100.zip / LIBKB-1.00 / SRC / MKKBNAME.PL < prev    next >
Perl Script  |  1996-07-23  |  2KB  |  97 lines

  1. #!/usr/bin/perl
  2. ##
  3. ## vi:ts=4
  4. ##
  5. ##---------------------------------------------------------------------------##
  6. ##  Author:
  7. ##      Markus F.X.J. Oberhumer         markus.oberhumer@jk.uni-linz.ac.at
  8. ##  Copyright:
  9. ##      Copyright (C) 1995, 1996 Markus F.X.J. Oberhumer
  10. ##      For conditions of distribution and use, see copyright notice in kb.h 
  11. ##  Description:
  12. ##      create _kbname.hh from kb.h
  13. ##---------------------------------------------------------------------------##
  14.  
  15. ($PROG = $0) =~ s%\\%/%g;
  16.  
  17. $keys = 0;
  18. %name = ();
  19.  
  20. #
  21. # read
  22. #
  23.  
  24. $kb = shift || 'kb.h';
  25. open(FILE,$kb) || die "$PROG: unable to open $kb: $!\n";
  26.  
  27. while (<FILE>) {
  28.  
  29. ##                       #   define   KB_SCAN_ESC       1
  30.     next unless (/^\s*\#\s*define\s+KB_SCAN_(\w+)\s+(\w+)/);
  31.     $n = $1; $c = $2;
  32.     next if ($c =~ /^KB_SCAN_/);    # an alias
  33.  
  34.     unless ($c =~ /^\d+$/) {
  35.         die "$PROG: line $.: invalid scancode $c for $n\n";
  36.     }
  37.     if (defined($name{$c})) {
  38.         die "$PROG: line $.: duplicate entry $c -> $name{$c} $n\n";
  39.     }
  40. ##    print STDERR "$PROG: $n $c\n";
  41.     $name{$c} = $n;
  42.     $keys++;
  43.  
  44. }
  45. close(FILE);
  46.  
  47. print STDERR "$PROG: $keys key names found\n";
  48.  
  49. if ($keys == 0) {
  50.     die "$PROG: no keys found !\n";
  51. }
  52.  
  53. #
  54. # write
  55. #
  56.  
  57. binmode(STDOUT);        # use unix end-of-line conventions
  58.  
  59. print <<Header;
  60. /* _kbname.hh -- key names
  61.  * Copyright (C) 1995, 1996 Markus F.X.J. Oberhumer
  62.  * For conditions of distribution and use, see copyright notice in kb.h 
  63.  */
  64.  
  65. /* WARNING: this file should *not* be used by applications. It is
  66.    part of the implementation of the keyboard library and is
  67.    subject to change. Applications should only use kb.h.
  68.  */
  69.  
  70.  
  71. /* DO NOT EDIT - this file is automatically generated by $PROG */
  72.  
  73.  
  74. static const char * const _kb_key_name[128] = {
  75. Header
  76.  
  77. for (0..127) {
  78.     local ($n, $s);
  79.     $n = '';
  80.     if (defined($name{$_})) {
  81.         $n = $name{$_};
  82.         $n =~ s/_/ /g;
  83.         $keys--;
  84.     }
  85.     $s = sprintf("\"%s\",", $n);
  86.     printf("\t%-16s\t/* %3d   0x%02x */\n", $s, $_, $_);
  87. }
  88.  
  89. if ($keys != 0) {
  90.     die "$PROG: $keys keys were not handled !\n";
  91. }
  92.  
  93. print "};\n\n";
  94. print "\n/*\nvi:ts=4\n*/\n";
  95.  
  96. exit(0);
  97.